﻿using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using XUCore.Ddd.Domain;
using XUCore.NetCore.FreeSql.Entity;
using XUCore.Paging;
using Microsoft.AspNetCore.Mvc;

namespace XUCore.NetCore.FreeSql.Curd
{
    /// <summary>
    /// CURD服务
    /// </summary>
    public interface ICurdService
    {
    }
    /// <summary>
    /// CURD服务
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    /// <typeparam name="TEntity">数据库实体</typeparam>
    /// <typeparam name="TDto">返回实体</typeparam>
    public interface ICurdService<TKey, TEntity, TDto> : ICurdService
        where TEntity : EntityFull<TKey>, new()
        where TDto : class, new()
    {
        /// <summary>
        /// 设置更新的列<para></para>
        ///     注意：标记 [Column(CanUpdate = false)] 的属性不会被更新
        /// </summary>
        /// <param name="id"></param>
        /// <param name="field"></param>
        /// <param name="value"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<int> UpdateFieldAsync(TKey id, string field, string value, CancellationToken cancellationToken = default);
        /// <summary>
        /// 批量设置更新的列<para></para>
        ///     注意：标记 [Column(CanUpdate = false)] 的属性不会被更新<para></para>
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="field"></param>
        /// <param name="value"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<int> BatchUpdateFieldAsync(TKey[] ids, string field, string value, CancellationToken cancellationToken = default);
        /// <summary>
        /// 物理删除数据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<int> DeleteAsync(TKey id, CancellationToken cancellationToken = default);
        /// <summary>
        /// 批量物理删除数据
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<int> BatchDeleteAsync(TKey[] ids, CancellationToken cancellationToken = default);
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<int> SoftDeleteAsync(TKey id, CancellationToken cancellationToken = default);
        /// <summary>
        /// 批量逻辑删除
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<int> BatchSoftDeleteAsync(TKey[] ids, CancellationToken cancellationToken = default);
        /// <summary>
        /// 根据id获取一条记录
        /// </summary>
        /// <param name="id"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<TDto> GetAsync(TKey id, CancellationToken cancellationToken = default);
    }
    /// <summary>
    /// CURD服务
    /// </summary>
    /// <typeparam name="TKey">主键类型</typeparam>
    /// <typeparam name="TEntity">数据库实体</typeparam>
    /// <typeparam name="TDto">返回实体</typeparam>
    /// <typeparam name="TCreateCommand">创建命令</typeparam>
    /// <typeparam name="TUpdateCommand">修改命令</typeparam>
    /// <typeparam name="TQueryCommand">查询列表命令</typeparam>
    /// <typeparam name="TQueryPageCommand">查询分页命令</typeparam>
    public interface ICurdService<TKey, TEntity, TDto, TCreateCommand, TUpdateCommand, TQueryCommand, TQueryPageCommand> : ICurdService<TKey, TEntity, TDto>
            where TEntity : EntityFull<TKey>, new()
            where TDto : class, new()
            where TCreateCommand : CreateCommand
            where TUpdateCommand : UpdateCommand<TKey>
            where TQueryCommand : ListCommand
            where TQueryPageCommand : PageCommand
    {
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<TDto> CreateAsync(TCreateCommand request, CancellationToken cancellationToken = default);
        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<int> UpdateAsync(TUpdateCommand request, CancellationToken cancellationToken = default);
        /// <summary>
        /// 查询列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<List<TDto>> GetListAsync(TQueryCommand request, CancellationToken cancellationToken = default);
        /// <summary>
        /// 查询分页列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<PagedModel<TDto>> GetPageAsync(TQueryPageCommand request, CancellationToken cancellationToken = default);
    }
}